#include "Ray3.h"

//Default constructor
Ray3::Ray3()
{
	origin = direction = Vector3(0.0f, 0.0f, 0.0f);
}

//Initialize ray - not normalized
Ray3::Ray3(const Vector3& o, const Vector3& d)
{
	origin = o;
	direction = d;
}

//Initialize Ray - normalized
Ray3::Ray3(const Vector3& o, const Vector3& d, bool normalized)
{
	origin = o;
	direction = d;
	if(normalized) direction.Normalize();
}

//functions
//Normalize the ray
void Ray3::NormalizeRay()
{
	direction.Normalize();
}

//PointAt
Vector3 Ray3::PointAt(float t)
{
	return (origin + (t*direction));
}

/*
Function	: RayIntersection
Params		: @1 - Ray3 - the ray with which intersection test is to be performed
			  @2 - float& t1 - the distance between the origin of first ray and point of intersection
			  @3 - float& t2 - the distance between the origin of second ray and point of intersection
Return type	: bool - Indicates if there is successful intersection between the rays
Desc		: This function is used as an intersection test between two rays. The first ray being the ray that calls this function and
			  the second ray being the ray that is to be used to compute intersection with.
*/
/*
bool Ray3::RayIntersection(Ray3& R2, float& t1, float& t2)
{
	/*
	Ray - Ray intersection routine
	-------------------------------
	Ray1 = o1 + t1.d1
	Ray2 = o2 + t2.d2

	For intersection:
					
					o1 + t1d1 = o2 + t2d2
					t1d1 = (o2-o1) + t2d2
					crossing by t2
					(t2 X t1) d1 = (t2 x (o2-o1))
					=> d1 = ( t2 x (o2-o1) )/(t2 x t1)
					multiplying and dividing by (t2 x t1)
					
					d1 = ((t2 x (o2-o1)).(t2 x t1))/|(t2 x t1)|^2
					
					if denominator |(t2 X t1)|^2 == 0 then no intersection
					
					similarly d2 = ((t1 X (o1-o2)).(t2Xt1))/|(t2 X t1)|^2
	

	Vector3 t2crosst1 = R2.direction ^ this->direction;
	


	return Ray3(1.0f, 1.0f, 1.0f);

}
*/